<?php
namespace app\mobile\model;
use think\Request;
use think\Session;

/**
 * Class ShopGoods
 * @package app\mobile\model 店铺商品表
 */
class ShopGoods extends BaseModel
{
    /*
     * 排序
     */
    public function get_condition($type)
    {
        $data = [
            ['sort'=>'desc','create_time'=>'desc'],  //综合
            ['sale_number'  => 'desc'],  //销量
            ['price'        =>  'asc'], //价格从低到高
            ['price'        =>  'desc'], //价格从高到低
        ];
        return $data[$type];
    }
    //商品和商品属性一对多
    public function shopSpecAttr()
    {
        return $this->hasMany('shopSpecAttr','goods_id','id');
    }
    //商品和商品规格一对多
    public function shopGoodsFlag(){
        return $this->hasMany('ShopGoodsFlag','goods_id','id');
    }
    //订单商品和订单商品属性一对一
    public function shopSpecAttrOrder()
    {
        return $this->hasOne('shopSpecAttr','goods_id','id');
    }
    //商品和店铺多对一
    public function shop()
    {
        return $this->belongsTo('Shop','member_id','member_id')->field('member_id,title');
    }
    public function condition($type)
    {
        $data = [
            [],
            ['sale_number'=>'desc'],
            ['create_time'=>'desc'],
            ['price'=>'asc'],
            ['price'=>'desc'],
        ];
        return $data[$type];
    }

//    public function getPicArrAttr($value)
//    {
//        return unserialize($value);
//    }
}